<template>
	<view>
		<view>
			<view class="cart" v-for="(item,index) in cart" :key="index">
				
				<van-checkbox :value="item.selected" @change="changeSelectState(item)" class="cart-check"></van-checkbox>
				
				<van-card :price="item.price" :title="item.name" :thumb="item.img" class="goodsinfo">
				
				  <template #footer>
					  	
							<van-stepper size="32" :value="item.count" min="1" max="10" @plus="countAdd(item)" @minus="countDec(item)" />
				  </template>
				</van-card>
				
<!-- 				<van-card :price="item.price" :title="item.name" :thumb="item.img" class="goodsinfo">
				</van-card>
				<van-stepper size="32" :value="item.num" min="1" max="10" @plus="inc(item)" @minus="dec(item)" /> -->
			</view>
		</view>

		
		<view>
<!-- 			<van-submit-bar class="van-submit-bar"
				 button-text="提交订单">
				<van-checkbox @change="checkAllHandler" v-model="checked">全选</van-checkbox>
			</van-submit-bar> -->
					
				<van-submit-bar :price="amount*100" button-text="提交订单" @submit="onSubmit" class="van-submit-bar">
				  <van-checkbox  :value="allSelected" @change="changeAll">全选</van-checkbox>
				  <template #tip>
				
				  </template>
				</van-submit-bar>
				
		</view>

	</view>
</template>

<script>
	import { mapGetters, mapMutations, mapState } from "vuex";
	export default {
		data() {
			return {
				allSelectedChe:true
				
			}
		},
		onLoad() {

		},
		onNavigationBarButtonTap(e){
	
			if(e.index==1){
				uni.switchTab({
					url:"../home/home"
				})
			}
			if(e.index==0){
	
		   //遍历对象
		   let id = [];
		   for (let key in this.seletedObj) {
		     if (this.seletedObj[key]) {
		       this.cart.forEach((item, i) => {
		         if (item.id == key) {
		           id.push(item.id);
		           this.cart.splice(i, 1);
		         }
		       });
		     }
		   }
		   this.delFromCart(id);
		
			}
		
		},
		
		
		   computed: {
				...mapState("me",['userInfo']),
		    ...mapState("cart", ["cart","allSelected"]),
			
		    ...mapGetters("cart", ["idstr","countObj","seletedObj","selectedcount","amount"])
		  },
		  methods: {
		    ...mapMutations("cart", ["countAdd","countDec","delFromCart","updateGoodsCount","changeSelectState","changeAll","getallselected","del"]),
			onChange(value){
				console.log(value)
				  this.updateGoodsCount({ id: this.id, count: value.detail });
			},
			onSubmit(){
			if (this.userInfo != null){
				uni.navigateTo({
					animationType: 'slide-in-left',
					animationDuration: 300,
					url: "../cart/submit-order"
				})
				
			}else{
				uni.navigateTo({
					animationType: 'slide-in-left',
					animationDuration: 300,
					url: "../home/login"
				})
		
		// 		uni.navigateTo({
		// 			animationType: 'slide-in-left',
		// 			animationDuration: 300,
		// 			url: "../cart/submitOrder"
		// 		})
				
				
				}
			}
			
		}
	}
</script>

<style scoped>
	/* @import "/wxcomponents/vant/common/index.wxss"; */
	.cart {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		
		background-color: #fafafa;


	}
	.van-submit-bar{
		position: relative !important;
		bottom: 100px !important;
		z-index: 99999;
	}
	.goodsinfo{
		width: 100%;
	}
	
	.cart-check{
		padding: 0 15px;
	}
	

</style>
